<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="期号" prop="expect">
        <el-input
          v-model="queryParams.expect"
          placeholder="请输入期号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开奖时间">
        <el-date-picker
          v-model="openTimeRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleSync"
          v-hasPermi="['game:lhc:sync']"
        >同步数据
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="主键" align="center" prop="id" width="80"/>
      <el-table-column label="期号" align="center" prop="expect"/>
      <el-table-column label="开奖时间" align="center" key="open_time" prop="open_time" width="160"/>
      <el-table-column label="红1" align="center" width="80">
        <template slot-scope="scope">
          <span class="red_number_top_circle number_top">{{ scope.row.red_num_1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="红2" align="center" width="80">
        <template slot-scope="scope">
          <span class="red_number_top_circle number_top">{{ scope.row.red_num_2 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="红3" align="center" width="80">
        <template slot-scope="scope">
          <span class="red_number_top_circle number_top">{{ scope.row.red_num_3 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="红4" align="center" width="80">
        <template slot-scope="scope">
          <span class="red_number_top_circle number_top">{{ scope.row.red_num_4 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="红5" align="center" width="80">
        <template slot-scope="scope">
          <span class="red_number_top_circle number_top">{{ scope.row.red_num_5 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="蓝1" align="center" width="80">
        <template slot-scope="scope">
          <span class="blue_number_top_circle number_top">{{ scope.row.blue_num_1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="蓝2" align="center" width="80">
        <template slot-scope="scope">
          <span class="blue_number_top_circle number_top">{{ scope.row.blue_num_2 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.game_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listCjdlt, syncCjdlt} from "@/api/metadata/game";

export default {
  name: "GameCjdlt",
  dicts: ['game_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      dataList: [],
      openTimeRange: [],
      // 查询参数
      queryParams: {
        page: 1,
        page_size: 10,
        expect: undefined,
        status: 3,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      listCjdlt(this.addDateRange(this.queryParams, this.openTimeRange, '_create_time')).then(response => {
          this.dataList = response.data;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.openTimeRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 同步按钮操作 */
    handleSync() {
      this.$modal.confirm('是否确认同步数据？').then(function () {
        return syncCjdlt({});
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("同步成功");
      }).catch(() => {
      });
    },
    numberColor(number) {
      const red_list = ["01", "02", "07", "08", "12", "13", "18", "19", "23", "24", "29", "30", "34", "35", "40",
        "45", "46"
      ]
      const blue_list = ["03", "04", "09", "10", "14", "15", "20", "25", "26", "31", "36", "37", "41", "42",
        "47", "48"
      ]
      const green_list = ["05", "06", "11", "16", "17", "21", "22", "27", "28", "32", "33", "38", "39", "43",
        "44", "49"
      ]
      if (red_list.indexOf(number.toString()) >= 0) {
        return "red_number_top_circle number_top";
      } else if (green_list.indexOf(number.toString()) >= 0) {
        return "green_number_top_circle number_top";
      } else if (blue_list.indexOf(number.toString()) >= 0) {
        return "blue_number_top_circle number_top";
      }
    },
  }
};
</script>
<style scoped lang="scss">
/*黑色数字加圈*/
.black_number_top_circle {
  background-color: #ff80ab;
  color: #fff;
}

/*蓝色数字加圈*/
.blue_number_top_circle {
  background-color: #0052d9;
  color: #fff;
}

/*红色数字加圈*/
.red_number_top_circle {
  background-color: red;
  color: #fff;
}

/*绿数字加圈*/
.green_number_top_circle {
  background-color: green;
  color: #fff;
}

.number_top {
  border-radius: 50%;
  width: 40 rpx;
  height: 40 rpx;
  line-height: 40 rpx;
  text-align: center;
  vertical-align: middle;
  display: inline-block;
  margin-left: 1px;
}
</style>
